package models

import (
	"time"
	"reflect"
	"github.com/astaxie/beego/validation"
)

type Company struct {
	Id int `orm:"auto"`
	Name string `form:"name" valid:"Required" validmsg:"请输入公司名"`
	Legal_person string 
	Legal_phone string 
	Staff_count int 
	Security_phone string 
	Is_poison int `form:"is_poisn"`
	Address string `form:"address" valid:"Required" validmsg:"请输入公司地址"`
	Lat string `form:"lat" valid:"Required" validmsg:"请选择地点"`
	Lng string `form:"lng" valid:"Required" validmsg:"请选择地点"`
	Created_at time.Time  `orm:"auto_now_add;type(datetime)"`
	Updated_at time.Time `orm:"auto_now;type(datetime)"`
	Image string
	Deleted_at time.Time `orm:"type(datetime)"`
}

func (this *Company) Valid () (b bool,msg string ){
	v:=validation.Validation{}
	b,_=v.Valid(this)
	if !b {
		st:= reflect.TypeOf(Company{})
		field,_:= st.FieldByName(v.Errors[0].Field)
		msg:= field.Tag.Get("validmsg")
		return b,msg
	}
	return true,""
}